<?php
namespace Endpoints\Tools;

use Endpoints\Base\Endpoint;
use OSS\Core\OssException;
use OSS\OssClient;
use Symfony\Component\Console\Input\InputArgument;
class GetOssObject extends Endpoint
{
    const ARGUMENT_FILE_ID = 'file_id';
    const ARGUMENT_IMG_OPTION = 'img_option';

    // 收参
    public function getArguments()
    {
        return [
            [static::ARGUMENT_FILE_ID,InputArgument::REQUIRED,'文件id',''],
            [static::ARGUMENT_IMG_OPTION,InputArgument::OPTIONAL,'图片选项',[]],
        ];
    }

    /**
     * 实现逻辑
     */
    public function dryRun()
    {
        $object       = $this->argument(static::ARGUMENT_FILE_ID);
        $imgOption[OssClient::OSS_PROCESS] = $this->argument(static::ARGUMENT_IMG_OPTION);
        $imgOption    = [];
        $accessId     = env("ALIYUN_OSS_ID");
        $accessSecret = env("ALIYUN_OSS_SECRET");
        $endpoint     = "https://oss-cn-beijing.aliyuncs.com/";
        $bucket       = "candy2019";
        $timeout      = 600;
        $object       = $object ?: "2019/12/26/WechatIMG432.jpeg";
        try{
            $ossClient = new OssClient($accessId, $accessSecret, $endpoint);
            $signedUrl = $ossClient->signUrl($bucket, $object, $timeout, "GET", $imgOption);
            return $signedUrl;
        } catch(OssException $e) {
            return '';
        }

    }
}